package com.bugsnag.ohos;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Stateful information set by the notifier about the device on which the event occurred can be
 * found on this class. These values can be accessed and amended if necessary.
 *
 * @since 2021-07-05
 */
public class DeviceWithState extends Device {
    private DeviceBuildInfo buildInfo;
    private boolean jailbroken;
    private String id;
    private String locale;
    private long totalMemory;
    private Map<String, Object> runtimeVersions = new HashMap<>();

    /**
     * The number of free bytes of storage available on the device
     */
    private long freeDisk;

    /**
     * The number of free bytes of memory available on the device
     */
    private long freeMemory;

    /**
     * The orientation of the device when the event occurred: either portrait or landscape
     */
    private String orientation;

    /**
     * The timestamp on the device when the event occurred
     */
    private Date time;

    /**
     * constructor
     *
     * @param buildInfo
     * @param jailbroken
     * @param id
     * @param locale
     * @param totalMemory
     * @param runtimeVersions
     * @param freeDisk
     * @param freeMemory
     * @param orientation
     * @param time
     */
    public DeviceWithState(DeviceBuildInfo buildInfo, boolean jailbroken, String id,
                           String locale, long totalMemory, Map<String, Object> runtimeVersions,
                           long freeDisk, long freeMemory, String orientation, Date time) {
        super(buildInfo, buildInfo.cpuAbis, jailbroken, id, locale, totalMemory, runtimeVersions);
        this.freeDisk = freeDisk;
        this.freeMemory = freeMemory;
        this.orientation = orientation;
        this.time = time;
    }

    public DeviceBuildInfo getBuildInfo() {
        return buildInfo;
    }

    public void setBuildInfo(DeviceBuildInfo buildInfo) {
        this.buildInfo = buildInfo;
    }

    public boolean getJailbroken() {
        return jailbroken;
    }

    public void setJailbroken(boolean jailbroken) {
        this.jailbroken = jailbroken;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    public long getTotalMemory() {
        return totalMemory;
    }

    public void setTotalMemory(long totalMemory) {
        this.totalMemory = totalMemory;
    }

    public Map<String, Object> getRuntimeVersions() {
        return runtimeVersions;
    }

    public void setRuntimeVersions(Map<String, Object> runtimeVersions) {
        this.runtimeVersions = runtimeVersions;
    }

    public long getFreeDisk() {
        return freeDisk;
    }

    public void setFreeDisk(long freeDisk) {
        this.freeDisk = freeDisk;
    }

    public long getFreeMemory() {
        return freeMemory;
    }

    public void setFreeMemory(long freeMemory) {
        this.freeMemory = freeMemory;
    }

    public String getOrientation() {
        return orientation;
    }

    public void setOrientation(String orientation) {
        this.orientation = orientation;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Override
    public void serializeFields(JsonStream writer) throws IOException {
        super.serializeFields(writer);
        writer.name("freeDisk").value(freeDisk);
        writer.name("freeMemory").value(freeMemory);
        writer.name("orientation").value(orientation);

        if (time != null) {
            writer.name("time").value(time);
        }
    }
}
